package com.su.lesson04;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class IconDemo extends JFrame implements Icon{
    private int width;
    private int height;

    public IconDemo(int width,int height){
        this.width=width;
        this.height=height;
    }

    public void  init(){

            IconDemo iconDemo = new IconDemo(15,15);
            JLabel label = new JLabel("icon",iconDemo,SwingConstants.CENTER);

            //设置容器
            Container container = getContentPane();
            container.add(label);

            //this指代的是这个函数，不能设置container可见！！！

            this.setVisible(true);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public static void main(String[] args) {
            new IconDemo(15,15).init();
    }
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }
}
